
import { getShopNotice } from '@/services';
import { IShopNotice } from '@/types';
import { Effect, Reducer } from 'umi';

export interface ShopNoticeModelState {
  shopNoticeList:IShopNotice[]
}
export interface ShopNoticeModelType {
  namespace: 'shopNotice';
  state: ShopNoticeModelState;
  effects: {
    getShopNotice: Effect;
  };
  reducers: {
    save: Reducer<ShopNoticeModelState>;
  };
}
const MenuModel: ShopNoticeModelType = {
  namespace: 'shopNotice',
  state: {
    shopNoticeList: [],
  },
  effects: {
    *getShopNotice({ payload }, { call, put, select }) {
      let result = yield call(getShopNotice, payload);
      if (result) {
        yield put({
          type: 'save',
          payload: {
            shopNoticeList: result.records.map((item: any,index:number) => {
              item.key = item.id;
              item.index = index+1
              return item;
            }),
          },
        });
      }
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};

export default MenuModel;
